<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        input,
        div {
            margin: 20px auto;
        }
    </style>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="demo">
        <!-- 
            简写,就是当不必设置 set函数 时,可将 fullName 直接设置为函数,值仍为函数的返回值
         -->
        <input type="text" v-model='firstName'><br>
        <input type="text" v-model='lastName'><br>
        <div>{{fullName}}</div>
    </div>
    <script>
        Vue.config.productionTip = false;

        new Vue({
            el: '#demo',
            data: {
                firstName: 'zhang',
                lastName: 'san'
            },
            //底层借助 Object.defineProperty()方法实现,存在getter和setter

            computed: {
                fullName(){     
                    let { firstName, lastName } = this;
                    return firstName[0].toUpperCase() + firstName.slice(1) + '-' + lastName
                }
            }

        })
    </script>
</body>

</html>